using System;
using System.Collections.Generic;
using System.Text;

namespace WindowsApplication1
{
  class ISOData
  {
    private int m_maxIterations;
      private double m_epsilon;

    public ISOData(int maxIterations, double epsilon)
    {
      m_maxIterations = maxIterations;
      m_epsilon = epsilon;
    }

    public void Compute(FeatureSpace featureSpace)
    {
      

      for (int iteration = 0; iteration < m_maxIterations; iteration++)
      {
        bool change = false;
        Feature[] groupCenters = featureSpace.GetCentersOfClasses();

        for (int iFeature = 0; iFeature < featureSpace.Features.Count; iFeature++)
        {
          Feature f = featureSpace.GetFeature(iFeature);
          double min = Double.MaxValue;
          int k = f.Class;
          for (int iGroup = 0; iGroup < groupCenters.Length; iGroup++)
          {
            double d = Vector.Distance(f.Vector, groupCenters[iGroup].Vector);
            if (d < min)
            {
              k = groupCenters[iGroup].Class;
              min = d;
            }
          }
          if (f.Class != k)
          {
            f.Class = k;
            change = true;
          }
          
        }

        if (!change)
          break;
      }
    }






  }
}
